package com.ytmz.gateway.config;

import com.ytmz.gateway.security.AuthorizationFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.route.Route;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;

@Component
@Configuration
public class GateWayRouteLocator implements RouteLocator {

    @Value("${gateway.route.system}")
    private String SYSTEM;
    @Value("${gateway.route.query}")
    private String QUERY;
    @Value("${gateway.route.service}")
    private String SERVICE;
    private ApplicationContext applicationContext;
    private RouteLocatorBuilder builder;

    public GateWayRouteLocator(ApplicationContext applicationContext, RouteLocatorBuilder builder) {
        this.applicationContext = applicationContext;
        this.builder = builder;
    }

    @Override
    public Flux<Route> getRoutes() {
        return this.builder.routes()
                .route("path_route", r -> r.path("/query/**").uri(QUERY))
                .route("path_route", r -> r.path("/service/**").uri(SERVICE))
                .route("path_route", r -> r.path("/**")
                        .uri(SYSTEM))
                .build().getRoutes();
    }
}
